package com.comdosoft.comdoandroidbase.util;

import android.os.Handler;
import android.view.View;

/**
 * 防止用户快速点击控件
 * 
 * @author niemin
 * 
 */
public class DoubleClick {

	/**
	 * 方法一,防止同一个控件快速点击
	 * 
	 * @param view
	 */
	public static void ForbidDoubleClick(final View view) {
		view.setClickable(false);
		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				view.setClickable(true);
			}
		}, 800);
	}

	public static long lastClickTime;

	/**
	 * 方法二，防止不同的控件快速点击
	 */
	public static boolean ForbidDoubleClick() {
		long time = System.currentTimeMillis();

		if ((time - lastClickTime) < 1200) {
			return false;
		}

		lastClickTime = time;
		return true;
	}
}
